package com.rm.zeyou.service.impl;

import cn.hutool.core.util.DesensitizedUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rm.zeyou.entity.Technician;
import com.rm.zeyou.entity.TechnicianAuthentication;
import com.rm.zeyou.mapper.TechnicianAuthenticationMapper;
import com.rm.zeyou.mapper.TechnicianMapper;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.TechnicianAuthenticationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rm.zeyou.util.check.CheckEmptyUtil;
import com.rm.zeyou.vo.response.SelectTechnicianAuthenticationResponseVo;
import com.rm.zeyou.vo.response.TechnicianAuthenticationList;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 技师资质表 服务实现类
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:09
 */
@Service
public class TechnicianAuthenticationServiceImpl extends ServiceImpl<TechnicianAuthenticationMapper, TechnicianAuthentication> implements TechnicianAuthenticationService {
    @Resource
    private TechnicianAuthenticationMapper technicianAuthenticationMapper;
    @Resource
    private TechnicianMapper technicianMapper;

    @Override
    public ApiRestResponse<SelectTechnicianAuthenticationResponseVo> selectTechnicianAuthentication(Long tid) {
        Technician technician = technicianMapper.selectById(tid);
        SelectTechnicianAuthenticationResponseVo vo = new SelectTechnicianAuthenticationResponseVo();
        vo.setTechnicianIdCard(DesensitizedUtil.idCardNum(technician.getIdCard(), 3, 2));
        List<TechnicianAuthentication> technicianAuthentications = technicianAuthenticationMapper.selectList(new LambdaQueryWrapper<TechnicianAuthentication>()
                .eq(TechnicianAuthentication::getTid, tid));

        List<TechnicianAuthenticationList> authenticationList = new ArrayList<>();
        if (!CheckEmptyUtil.isEmpty(technicianAuthentications)) {
            technicianAuthentications.forEach(item -> {
                TechnicianAuthenticationList vo1 = new TechnicianAuthenticationList();
                vo1.setAptitudeName(item.getAptitudeName());
                vo1.setAptitudePicture(item.getAptitudePicture());
                authenticationList.add(vo1);
            });
        }
        vo.setTechnicianAuthenticationList(authenticationList);

        return ApiRestResponse.success(vo);
    }
}
